#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define PI(i) pi[i-1]
#define Q(i) q[i-1]
#define P(i) p[i-1]


int computeprefix(char *q,int *pi,int m)
{
	int i,j,k;
	k=0;
	PI(1)=0;
	for(j=2;j<=m;j++)
	{
		while(k>0&&Q(k+1)!=Q(j)) k=PI(k);
		if(Q(k+1)==Q(j)) k=k+1;
		PI(j)=k;
	}
	return 0;
}

int kmpmatcher(char *p,int n,char *q,int m,int *pi)
{
	int i,j,k;
	i=1;
	k=1;
	while(i<=n)
	{
		if(P(i)==Q(k))
		{
			k++;
			i++;
			if(k==m) return (i-k);
		}
		else
		{
			if(k==1)
			{
				i++;
				continue;
			}
			k=PI(k-1)+1;
		}
	}
	return 0;
}


int main()
{
	int i,j,k;
	int n,m;
	int *pi;
	char *p,*q;
	scanf("%d %d",&n,&m);
	p=(char *)malloc((n+1)*sizeof(char));
	q=(char *)malloc((m+1)*sizeof(char));
	pi=(int *)malloc((m+1)*sizeof(int));
	scanf("%s",p);
	scanf("%s",q);
	m=strnlen(q,m);
	n=strnlen(p,n);
	computeprefix(q,pi,m);
	k=kmpmatcher(p,n,q,m,pi);
	printf("string matches at %d\n",k);
	free(p);
	free(pi);
	free(q);
	return 0;
}

